//
//  ShopDetailsViewController.m
//  NordsonTesco
//
//  Created by mac on 16/6/27.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ShopDetailsViewController.h"
#import "TheMapViewController.h"
@interface ShopDetailsViewController ()
{
    NSString *string_collection;//收藏判断
    UIButton *collectionButton;// 收藏button
}
@end
@implementation ShopDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self ShopDetailsAction];
    self.title = @"店铺信息";
    string_collection = @"YES";
    
    UIButton *shopDetailsBackButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [shopDetailsBackButton addTarget:self action:@selector(shopDetailsBackButtonAction) forControlEvents:UIControlEventTouchUpInside];
    CGSize shopDetailsBackButtonSize = CGSizeMake(15, 30);
    shopDetailsBackButton.frame = CGRectMake(shopDetailsBackButton.frame.origin.x, shopDetailsBackButton.frame.origin.y, shopDetailsBackButtonSize.width, shopDetailsBackButtonSize.height);
    shopDetailsBackButton.titleLabel.font = [UIFont boldSystemFontOfSize:12];
    [shopDetailsBackButton setImage:[UIImage imageNamed:@"arrow---left"] forState:UIControlStateNormal];
    UIBarButtonItem *leftButtonItem = [[UIBarButtonItem alloc] initWithCustomView:shopDetailsBackButton];
    self.navigationItem.leftBarButtonItem = leftButtonItem;
    
    //收藏
    collectionButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [collectionButton addTarget:self action:@selector(collectionButtonAction) forControlEvents:UIControlEventTouchUpInside];
    CGSize collectionButtonSize = CGSizeMake(30, 30);
    collectionButton.frame = CGRectMake(collectionButton.frame.origin.x, collectionButton.frame.origin.y, collectionButtonSize.width, collectionButtonSize.height);
    collectionButton.titleLabel.font = [UIFont boldSystemFontOfSize:12];
    [collectionButton setImage:[UIImage imageNamed:@"shou"] forState:UIControlStateNormal];
    UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithCustomView:collectionButton];
    self.navigationItem.rightBarButtonItem = rightButtonItem;
    
    // Do any additional setup after loading the view from its nib.
}
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}
- (void)shopDetailsBackButtonAction{
    NSLog(@"返回");
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark -- 收藏
- (void)collectionButtonAction{
    
    if ([string_collection isEqualToString:@"YES"]) {
        NSLog(@"收藏");
        [collectionButton setImage:[UIImage imageNamed:@"STAR"] forState:UIControlStateNormal];
        string_collection = @"NO";
    }else{
        NSLog(@"取消收藏");
        [collectionButton setImage:[UIImage imageNamed:@"shou"] forState:UIControlStateNormal];
        string_collection = @"YES";
    }
}

#pragma  mark -- 店铺位置以及电话
- (IBAction)storeLocationAndPhone:(UIButton *)sender {
    switch (sender.tag) {
        case 444:{
            //            NSLog(@"店铺位置");
            TheMapViewController *mapVC = [[TheMapViewController alloc]init];
            [self.navigationController pushViewController:mapVC animated:YES];
        }
            break;
        case 445:{
            NSLog(@"电话");
        }
            break;
        default:
            break;
    }
}

#pragma mark -  轮播图
- (void)ShopDetailsAction{
    _shopDetailsScrollView = [[UIScrollView alloc]initWithFrame: CGRectMake(0,0,kScrernWidth,230)];
    _shopDetailsScrollView.contentSize = CGSizeMake(kScrernWidth*3,200);
    _shopDetailsScrollView.backgroundColor = [UIColor orangeColor];
    _shopDetailsScrollView.pagingEnabled = YES;
    _shopDetailsScrollView.delegate = self;
    //    _scrollView.bounces = NO;
    _shopDetailsScrollView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:_shopDetailsScrollView];
    
    for (int i = 0; i < 3; i ++) {
        UIImageView *imgView = [[UIImageView alloc]init];
        imgView.frame = CGRectMake(i*_shopDetailsScrollView.bounds.size.width,0, _shopDetailsScrollView.bounds.size.width, _shopDetailsScrollView.bounds.size.height);
        NSString *name = [NSString stringWithFormat:@"%d-V3", i + 1];
        imgView.image = [UIImage imageNamed:name];
        [_shopDetailsScrollView addSubview:imgView];
    }
    
    _shopDetailsPageControl = [[UIPageControl alloc]init];
    _shopDetailsPageControl.frame = CGRectMake(_shopDetailsScrollView.center.x - 60,210, 120, 20);
    [_shopDetailsPageControl addTarget:self action:@selector(Changepag:) forControlEvents:UIControlEventEditingChanged];
    _shopDetailsPageControl.numberOfPages = 3;
    _shopDetailsPageControl.currentPage = 0;
    [self.view addSubview:_shopDetailsPageControl];
}
- (void)Changepag:(UIPageControl *)pag{
    [_shopDetailsScrollView setContentOffset:CGPointMake(pag.currentPage*self.view.frame.size.width,0 /*page.currentPage*480*/) animated:YES];
}

#pragma  - mark UIScrollViewDelegate
//监听滚动的位置,改变pageCotrol的currentPage的值.
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat scrollviewW =  scrollView.frame.size.width;
    CGFloat x = scrollView.contentOffset.x;
    int page = (x + scrollviewW / 2) /  scrollviewW;
    _shopDetailsPageControl.currentPage = page;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
